from flask import Flask

from .init_sqlalchemy import db, ma, init_databases
from .init_login import init_login_manager
from .init_template_directives import init_template_directives
from .init_error_views import init_error_views
from .init_mail import init_mail, mail as flask_mail
from .init_upload import init_upload
from .init_migrate import init_migrate
from .init_session import init_session
from .template_global import register_template_global
from .init_redis import init_redis
from .init_scheduler import init_task_scheduler
from .init_simple_i18n import init_simple_i18n
from .init_plugins import init_plugins
from .init_websocket import init_websocket
from .init_log import init_logging
from .init_themes import init_themes_modules
from .init_plugin_manager import init_plugin_manager_ext
from apps.common.utils.route_manager import get_route_manager
from apps.extensions.init_route_interceptor import init_route_interceptor


def init_exts(app: Flask) -> None:
    init_logging(app)
    # 注册 Flask 功能
    init_login_manager(app)
    init_databases(app)
    init_mail(app)
    init_upload(app)
    init_migrate(app)
    init_session(app)
    init_template_directives(app)
    init_error_views(app)
    init_task_scheduler(app)
    # 初始化 Redis
    init_redis(app)
    # 初始化简化多语言支持
    init_simple_i18n(app)
    # 注册模板全局函数
    register_template_global(app)
    # 初始化插件
    # init_plugins(app)
    init_plugin_manager_ext(app)
    # 初始化 WebSocket
    init_websocket(app)
    init_themes_modules(app)
    get_route_manager(app)
    # 初始化路由拦截器
    init_route_interceptor(app)


